package observerPattern.observerAPattern;


/**
 * @program: course
 * @author: lsn
 * @create: 2024-05-05 09:24
 * @description: 角色：具体观察者
 */
public class CustomerTwo implements Observer{
    Subject subject;
    double oldPrice, newPrice;
    String personName;

    public CustomerTwo(Subject subject, String personName) {
        this.subject = subject;
        this.personName = personName;
        subject.addObserver(this);
    }

    @Override
    public void update() {
        if (subject instanceof ShopSubject){
            oldPrice = ((ShopSubject) subject).getOldPrice();
            newPrice = ((ShopSubject) subject).getNewPrice();
            System.out.println(personName + "只对商品的原价和折扣后的价格感兴趣：");
            System.out.println("原价是:" + oldPrice);
            System.out.println("现价是:" + newPrice);
        }
    }
}

